<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Leads extends CI_Controller {

	public function __construct(){
		parent::__construct();

		// load helper
		$this->load->helper('url');
		$this->load->library('session');

		// load model
		$this->load->model("Lead", '', TRUE);
		$this->load->model("Mem", '', TRUE);
	}	

	public function index(){

		$data['leads'] = $this->Lead->get_leads();

		$data['topEarn'] = $this->Mem->topEarn();

		if(count($data['leads']) > 0){
			$this->session->set_userdata('oldLeadId', $data['leads']['0']->leadId);
		} else{
			$this->session->set_userdata('oldLeadId', 0);
		}

        $data['mainView'] = 'index';
        $data['controllerName'] = 'admin/leads';
        $this->load->view('admin/layouts/layout', $data);
	}

	public function get_new_leads(){

		$oldLeadId = $this->session->userdata('oldLeadId');
		$data['leads'] = $this->Lead->get_new_leads($oldLeadId);

		if(count($data['leads']) > 0){

			$this->session->set_userdata('oldLeadId', $data['leads']['0']->leadId);

		    foreach ($data['leads'] as $lead)
		    {
		      echo "<li class='list-group-item'>";
		        echo "<div class='alert alert-success'>";
		          echo "<span class='label label-success networkName'>" . $lead->networkName . "</span>";
		          echo "<span class='alert-link lead-time'>";
		          	echo "<abbr class='timeago' title='" . $lead->time . "'>";
		          		echo $lead->time;
		          	echo "</abbr>";
		          echo "</span>";	
		          echo "<a href='' class='memberName'>";
		            echo "<h4 style='display: inline-block'>" . $lead->memberName . "</h4>";
		          echo "</a>";
		          echo "vừa lead con <span class='alert-link offerId' style='color: #A94442'>" . $lead->offerId . "</span>";
		          echo "<span class='badge'>+" . $lead->point . "</span>";
		        echo "</div>";
		      echo "</li>";
		    }
		}	

		else{
			echo 0;
		}	
	}

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */